package array;

import java.util.ArrayList;
import java.util.Optional;

public class LeetCode2609 {
    public static void main(String[] args) {
        int[] nums = {-1,0,3,4,6,10,13,14};
        int target = 13;
        System.out.println(search(nums, target));
    }
    public static int search (int[] nums, int target) {
        // write code here
        int left = 0;
        int right = nums.length - 1;
        int mid = (left + right) / 2;
        while (left <= right){
            if(nums[mid] == target) return mid;
            if(nums[mid] > target){
                right = mid - 1;
            }
            if(nums[mid] < target){
                left = mid + 1;
            }
            mid = (left + right) / 2;
        }
        return -1;
    }
    public static int findTheLongestBalancedSubstring(String s) {
        char[] sc = s.toCharArray();
        int zero = 0;
        int one = 0;
        int max = 0;
        for (int i = 0; i < sc.length; ) {
            while (i < sc.length && sc[i] == '0'){
                i++;
                zero++;
            }
            while (i < sc.length && zero > 0 && sc[i] == '1'){
                zero--;
                i++;
                one++;
            }
            if(zero == 0 && one == 0) i++;
            max = Math.max(max,one * 2);
            zero = 0;
            one = 0;
        }
        return max;
    }
}
